<template>
  <div class="app-container">

    <!-- 添加或修改房屋收费标准对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="960px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            <el-form-item label="组织机构" prop="deptName">
              <el-input v-model="form.deptName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="房屋名称" prop="roomName">
              <el-input v-model="form.roomName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="费用类型" prop="projectType">
              <el-input v-model="form.feeCondition.projectType" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            <el-form-item label="收费项目" prop="chargeName">
              <el-input v-model="form.feeCondition.chargeName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="收费标准" prop="normNames">
              <el-input v-model="form.feeCondition.normNames" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="开始收费时间" prop="beginChargeTime">
              <el-date-picker clearable
                              v-model="form.beginChargeTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择开始收费时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8" :xs="24">
            <el-form-item label="结束收费时间" prop="finishChargetime">
              <el-date-picker clearable
                              v-model="form.finishChargetime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择结束收费时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="指定金额" prop="amountSpecified">
              <el-input v-model="form.amountSpecified" placeholder="请输入指定金额" />
            </el-form-item>
          </el-col>
          <el-col :span="8" :xs="24">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { getRoomNorm, updateRoomNorm } from "@/api/payfee/roomNorm";

  export default {
    name: "RoomNormUpdate",
    data() {
      return {
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {
          feeCondition:{
            projectType:null,
            chargeName:null,
            normNames:null
          }
        },
        // 表单校验
        rules: {

        }
      };
    },
    created() {

    },
    methods: {
      show(id){
        this.reset();
        getRoomNorm(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改房屋收费标准";
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
        this.$emit("cancel")
      },
      // 表单重置
      reset() {
        this.form = {
          roomNormId: null,
          projectId: null,
          chargeId: null,
          normId: null,
          deptId: null,
          communityId: null,
          floorId: null,
          unitId: null,
          roomId: null,
          beginChargeTime: null,
          finishChargetime: null,
          amountSpecified: null,
          penaltyType: null,
          beginChargeableTime: null,
          finishChargeableTime: null,
          state: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          ancestors: null,
          deptName:null,
          roomName:null,
          feeCondition:{
            projectType:null,
            chargeName:null,
            normNames:null
          }

        };
        this.resetForm("form");
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.roomNormId != null) {
              updateRoomNorm(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.cancel();
              });
            }
          }
        });
      }
    }
  };
</script>
